/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc68;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc68Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc68QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc68Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-28
**/
@Service
@RequiredArgsConstructor
public class TransferIc68ServiceImpl extends ServiceImpl<TransferIc68Mapper, TransferIc68> implements TransferIc68Service {

    private final TransferIc68Mapper transferIc68Mapper;

    @Override
    public PageResult<TransferIc68> queryAll(TransferIc68QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc68Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc68> queryAll(TransferIc68QueryCriteria criteria){
        return transferIc68Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc68 resources) {
        transferIc68Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc68 resources) {
        TransferIc68 transferIc68 = getById(resources.getAaz703());
        transferIc68.copy(resources);
        transferIc68Mapper.updateById(transferIc68);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc68Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc68> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc68 transferIc68 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("系统跟踪流水号", transferIc68.getAaz341());
            map.put("转出地行政区划代码", transferIc68.getAab301());
            map.put("转出地人员编号", transferIc68.getAac319());
            map.put("人员编号", transferIc68.getAac001());
            map.put("姓名", transferIc68.getAac003());
            map.put("年度", transferIc68.getAae001());
            map.put("开始月份", transferIc68.getAae041());
            map.put("终止月份", transferIc68.getAae042());
            map.put("月缴费基数", transferIc68.getAae180());
            map.put("当地上年度在岗职工月平均工资", transferIc68.getAaa015());
            map.put("人员转移流水号", transferIc68.getAae062());
            map.put("转移数据来源", transferIc68.getAac306());
            map.put("人员参保关系ID", transferIc68.getAaz159());
            map.put("备注", transferIc68.getAae013());
            map.put("经办人", transferIc68.getAae011());
            map.put("经办时间", transferIc68.getAae036());
            map.put("经办机构", transferIc68.getAab359());
            map.put("业务日志ID", transferIc68.getAaz002());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
